package com.framework.boc.admin.controller;


import com.framework.boc.admin.entity.ContractInfo;
import com.framework.boc.admin.entity.MaterialInfo;
import com.framework.boc.admin.entity.OrderInfo;
import com.framework.boc.admin.service.impl.ContractInfoServiceImpl;
import com.framework.boc.admin.service.impl.MaterialInfoServiceImpl;
import com.framework.boc.admin.service.impl.OrderInfoServiceImpl;
import com.framework.boc.response.CommonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.framework.boc.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Leil
 * @since 2020-08-27
 */
@RestController
@RequestMapping("/admin/order-info")
public class OrderInfoController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    OrderInfoServiceImpl orderInfoService;
    @Autowired
    ContractInfoServiceImpl contractInfoService;
    @Autowired
    MaterialInfoServiceImpl materialInfoService;

    @GetMapping("/order")
    public CommonResponse queryOrderInfo(@RequestParam("merchantNo") String merchantNo) {
        logger.info("查询订单信息...merchantNo = " + merchantNo);

        List<OrderInfo> listOrderInfo = orderInfoService.queryOrderInfo(merchantNo);

        for(OrderInfo order : listOrderInfo){
            List<ContractInfo> listContractInfo = contractInfoService.queryContractInfo(order.getOrderNo());
            for(ContractInfo contract : listContractInfo){
                List<MaterialInfo> listMaterialInfo = materialInfoService.queryContractInfo(contract.getOrderNo(),contract.getVbillCode());
                contract.setListMaterialInfo(listMaterialInfo);
            }
            order.setListContractInfo(listContractInfo);
        }

        return CommonResponse.success(listOrderInfo);
    }
}

